/*!
 * This file implements a list of albums.
 * THIS FILE IS NOT USED FOR THE MOMENT
 * @author Mazzer Yannis, Calingarayar Martial
 * @file movies.h
 */
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QModelIndex>
#include "../liteconnector/liteconnector.h"
#include "albums.h"
#include "album/album.h"

Albums::Albums(QSqlDatabase &db, QWidget *parent) : QSqlTableModel(parent)
{
    connect(this, SIGNAL(layoutChanged()), this, SLOT(updateAlbumList()));
}

Albums::~Albums()
{
    int size = this->albums.size();
    for( int i = 0; i < size; i++) {
	delete albums.value(i);
    }
}

Album *Albums::getAlbum(const int &AlbumNumber)
{
    return this->albums[AlbumNumber];
}

Album *Albums::getAlbum(const QModelIndex &albumIndex)
{
    return this->albums[albumIndex.row()];
}

AlbumList Albums::getAlbumList()
{
    return this->albums;
}

int Albums::addAlbum(Album *newAlbum, bool ok)
{
    if(albums.contains(newAlbum)) {
	ok = false;
	return albums.indexOf(newAlbum);
    }
    else {
	this->albums.append(newAlbum);
	return 0;
    }
}

void Albums::removeAlbum(Album *oldAlbum)
{
//    int index = albums.indexOf(oldAlbum);
//    this->albums.removeAt(index);
}

void Albums::updateAlbumList()
{
//    int size = this->rowCount();
//    if(size != -1) {
//	for(int i = 0; i<size; i++) {
//	    QSqlRecord tmp = this->record(i);
//	    Album *newAlbum = new Album(tmp);
//	    this->albums.append(newAlbum);
//	}
//    }
}
